#include <iostream>
#include <vector>

using namespace std;

class Solution
{
public:
    int maxSubarraySumCircular(vector<int> &nums)
    {
        int globalMax = nums[0];
        int currentMax = nums[0];
        int globalMin = nums[0];
        int currentMin = nums[0];
        int sum = nums[0];
        for (int i = 1; i < nums.size(); i++)
        {
            int num = nums[i];
            sum += num;
            currentMax = max(currentMax + num, num);
            globalMax = max(globalMax, currentMax);
            currentMin = min(currentMin + num, num);
            globalMin = min(globalMin, currentMin);
        }
        if (globalMax < 0)
        {
            return globalMax;
        }
        return max(globalMax, sum - globalMin);
    }
};

int main()
{
    cout << "Code918" << endl;
    Solution s;
    vector<int> v{5, -3, 5};
    cout << s.maxSubarraySumCircular(v);
    return 0;
}